﻿<%@include file="/WEB-INF/jsp/taglib.jsp" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <c:import url="/WEB-INF/jsp/frontend/head.jsp" />
    <c:import url="/WEB-INF/jsp/frontend/activity/head.jsp" />
    <title>Activity</title>

    <script>
        function releaseCheck() {
            if(releaseFrom.release_content.value == "" ||  releaseFrom.release_content.value == null) {
                alert("发帖内容不能为空！");
                releaseFrom.release_content.focus();
                return false;
            }
            return true;
        }

        function replyCheck(thisBlock) {
            if(thisBlock.html() == "</br>" ||  thisBlock.html() == null || thisBlock.html() == "") {
                alert("发帖内容不能为空！");
                thisBlock.focus();
                return false;
            }
        }

        function showInfloor(infloorId, idx,obj) {
            var Url = "<spring:url value="/activityInfloor" />";
            $.ajax({
                type: "POST",
                cache: false,
                async: false,
                url: Url,
                data: {"infloor_id":infloorId},
                dataType: "html",
                success: function (data) {
                    $("#reply_infloor_list" + idx).html(data);
                    open_reply(obj);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("查找失败");
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                }
            });
        }

    </script>



</head>
<body>

<div class="head">

    <c:import url="/WEB-INF/jsp/frontend/header.jsp" />
</div>

<div class="row" id="container">

    <div class="col-md-6 col-md-3" id="user">

        <div id="user-info">
            <div id="person"></div>
            <div id="intro">
                <div id="person_name">${activity.activityPubName}</div>
                <div id="introduction">活动简介：${activity.activityPubIntro}</div>
                <div class="tele">电话：13345678265</div>
                <div class="mail">邮箱：${activity.activityPubContact}</div>
            </div>
        </div>
        <hr style="width: 88%; background-color: #004a86; height: 1px; margin-top: 40px; margin-left: auto">
        <div class="join_list">参与者列表</div>
        <div id="join-lists">

            <c:forEach items="${activityJoins}" var="activityJoin" end="2">
                <li class="join_lists">
                    <div class="joins_head"></div>
                    <div class="joins_name">${activityJoin.joinUserName}</div>
                </li>
            </c:forEach>

        </div>
    </div>


    <div class="col-md-12 col-md-6" id="topics">
        <div class="activity-container">
            <div class="activity-content">
                <div class="main-activity-theme">${activity.activityName}</div>
                <div class="main-activity-person">
                    <div class="main-activity-person-head" style="cursor: pointer" onclick="window.location.href='<spring:url value='/personalCenter/index/${activity.activityPub}' />'"></div>
                    <div class="main-activity-person-name">${activity.activityPubName}</div>
                    <div class="main-activity-person-time"><fmt:formatDate value="${activity.activityDate}"  type="date" dateStyle="default"/></div>
                </div>
                <div class="main-activity-content">${activity.activityContentText}</div>
            </div>
            <div class="poster"></div>

        </div>
        <div class="main-activity-foot">
            <div class="join-btn" id="joinActivity">参加</div>
            <div class="share">分享</div>
            <div class="share-img"></div>
            <div class="collection">收藏</div>
            <div class="collection-img"></div>

        </div>
        <div class="joins-already">
            <c:choose>
                <c:when test="${fn:length(activityJoins) > 0}">
                    <c:forEach items="${activityJoins}" var="activityJoin" end="2">
                        ${activityJoin.joinUserName}、
                    </c:forEach>
                    ...等<span>${fn:length(activityJoins)} </span>人已参与
                </c:when>
                <c:otherwise>
                    暂无人员参加
                </c:otherwise>
            </c:choose>
        </div>


        <div class="passage-reply">
            <%--<div class="reply-num">--%>
                <%--<b id="reply-num-word">11条评论</b>--%>
                <%--<div id="line">--%>
                <%--</div>--%>
            <%--</div>--%>


            <div class="reply-container">

                <div id="reply_block_list">
                    <jsp:include page="/WEB-INF/jsp/frontend/activity/activityMainReplyList.jsp" flush="true"/>
                </div>
                <div id="close" style="display: none"></div>
            </div>


            <div style="height: 400px;float: left" >

            </div>


            <div class="submit-reply">
                <p>发表回复</p>
            </div>
            <form id="replyForm" action method="post">
                <div contenteditable="true" class="my-reply-content" id="reply-input" name="reply_content"></div>
                <input type="hidden" name="activity_id" value="${activity.activityId}">
                <button type="button" class="btn btn-primary" id="submit-reply-btn">发表</button>
            </form>

            <%--<script>--%>
            <%--jQuery("#submit-button").click(function () {--%>
            <%--jQuery.post("addReply", {--%>
            <%--pid: ${blog.blogId},--%>
            <%--content: jQuery("#reply-input").text()}, function (res) {--%>
            <%--if (res === "true") {--%>
            <%--location.reload();--%>
            <%--}--%>
            <%--});--%>
            <%--});--%>
            <%--</script>--%>
        </div>
    </div>


<div class="col-md-6 col-md-3" id="activity">

    <div style="font-size: 18px; margin-bottom: 10px; margin-left: 10px;">活动列表</div>
    <div class="activity-list">
        <div id="activity_block_list">
            <jsp:include page="/WEB-INF/jsp/frontend/community/blockList/activityBlockList.jsp" flush="true"/>
        </div>
        <a href=""><div class="see-all" style="margin-right: 40px;">查看全部</div></a>
    </div>
    <img src="images/contact.png" style="margin-left: 18px;">
</div>

</div>

</body>
<c:import url="/WEB-INF/jsp/frontend/script.jsp" />

<script>

    function open_reply(obj) {
        $(obj).hide();
        $(obj).next().show();
//        $(obj).parent().parent().next().show();
        jQuery(obj).parent().parent().next().animate({height:"toggle"},300);
    }

    function close_reply(obj) {
//        jQuery(obj).parent().parent().parent().next().animate({height:"toggle"},300,function () {
            $(obj).hide();
            $(obj).parent().parent().next().hide();
            $(obj).prev().show();
//        });

    }


    function open_reply_reply(obj) {
        $(obj).parent().parent().parent().parent().next().find("#open-my-reply").click();
    }

    var activityReplyUrl = "<spring:url value="/activityReply" />";
    var replyForm = $("#replyForm");
    var replyBtn = $("#submit-reply-btn");

    replyBtn.click(function () {
        var temp = $("#reply-input");
        replyCheck(temp);
        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: activityReplyUrl,
            data: {"reply_content": temp.html(), "activity_id":'${activity.activityId}'},
            dataType: "html",
            success: function (data) {
                    alert("成功");
                    $("#reply_block_list").html(data);
                    temp.html("");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("回复失败");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
        return false;
    });

    var infloorUrl = "<spring:url value="/activityInfloorReply" />";

    function infloorSend(infloor, idx) {
        var temp = $("#infloor-reply"+idx);
        replyCheck(temp);
        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: infloorUrl,
            data: {"infloor_reply_content": temp.html(), "infloor":infloor},
            dataType: "html",
            success: function (data) {
                alert("成功");
                $("#reply_infloor_list" + idx).html(data);
                temp.html("");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("回复失败");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
        return false;
    }

    var activityJoinUrl = "<spring:url value="/activityJoin" />";
    var joinDiv = $("#joinActivity");

    joinDiv.click(function () {
        $.ajax({
            type: "GET",
            cache: false,
            async: false,
            url: activityJoinUrl,
            data: {"aid":'${activity.activityId}'},
            dataType: "json",
            success: function (data) {
                if(data.success ) {
                    alert("参加成功");
                    location.reload(true);
                }else {
                    alert(data.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("参加失败");
//                alert(XMLHttpRequest.status);
//                alert(XMLHttpRequest.readyState);
//                alert(textStatus);
            }
        });
        return false;
    });

</script>
</html>
